package org.redhat.auth.security.core;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.redhat.auth.security.resources.ResourceService;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.SecurityConfig;
import org.springframework.security.web.FilterInvocation;
import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;
import org.springframework.security.web.util.AntUrlPathMatcher;
import org.springframework.security.web.util.UrlMatcher;

/**
 * 本类加载资源定义，资源定义从数据库中读取，而不是在xml中配置
 * 
 * @author lingen.liu
 * 
 */
public class AuthSecurityMetadataSource implements
		FilterInvocationSecurityMetadataSource {

	private ResourceService resourceService;

	@Override
	public Collection<ConfigAttribute> getAllConfigAttributes() {
		return resourceService.getAllConfigAttributes();
	}

	@Override
	public Collection<ConfigAttribute> getAttributes(Object object)
			throws IllegalArgumentException {
		String url = ((FilterInvocation) object).getRequestUrl();
		return resourceService.getAttributes(url);
	}

	@Override
	public boolean supports(Class<?> arg0) {
		return true;
	}

	public ResourceService getResourceService() {
		return resourceService;
	}

	public void setResourceService(ResourceService resourceService) {
		this.resourceService = resourceService;
	}

}